package com.ruibang.glass.equipment.service.impl.device;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.equipment.domain.req.device.DeviceAllPageReq;
import com.ruibang.glass.equipment.entity.device.PointCheckRecord;
import com.ruibang.glass.equipment.mapper.device.PointCheckRecordMapper;
import com.ruibang.glass.equipment.service.PointCheckRecordService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;


@Slf4j
@Service
public class PointCheckRecordServiceImpl extends ServiceImpl<PointCheckRecordMapper, PointCheckRecord> implements PointCheckRecordService {


    @Override
    public IPage<PointCheckRecord> getPointRecordList(DeviceAllPageReq deviceAllPageReq) {
        return baseMapper.getCheckRecordList(new Page<>(deviceAllPageReq.getPageNo(), deviceAllPageReq.getPageSize()), deviceAllPageReq);
    }

    @Override
    public ResultBody addOrUpdateCheck(PointCheckRecord point) {
        if (StringUtils.isBlank(point.getId())) {
            baseMapper.insert(point);
            return ResultBody.success();
        }
        baseMapper.updateById(point);
        return ResultBody.success();
    }

    @Override
    public Date getNewDateById(String id) {
        return baseMapper.getNewDateById(id);
    }

}
